package com.point.ootb.domain.enity;

import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsKey;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @IsKey
    @Column(type = MySqlTypeConstant.BIGINT, isKey = true, isNull = false, comment = "数据id, 雪花算法生成")
    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    @Column(type = MySqlTypeConstant.DATETIME, comment = "记录创建时间, 应用层更新")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @Column(type = MySqlTypeConstant.BIGINT, comment = "记录创建用户id, 应用层更新")
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private Long createBy;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    @Column(type = MySqlTypeConstant.DATETIME, comment = "记录更新时间, 应用层更新")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    @Column(type = MySqlTypeConstant.BIGINT, comment = "记录更新用户id, 应用层更新")
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;

    @Column(type = MySqlTypeConstant.BIGINT, defaultValue = "0", comment = "删除标识符, 0未删除,  其他值为删除. 其他可以设置为该记录id, 这样可以针对唯一字段+deleted字段组合成唯一索引, 数据库层面保证数据不重复")
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    @TableLogic(value = "0")
    private Long deleted;
}
